﻿using System.Collections.ObjectModel;
using AIStudio.Wpf.Controls.Bindings;
using AIStudio.Wpf.Controls;

namespace WpfApp1
{
    public class MainWindowViewModel : BindableBase
    {
        private IList<DemoDataModel> _dataList;
        public IList<DemoDataModel> DataList
        {
            get { return _dataList; }
            set
            {
                if (_dataList != value)
                {
                    _dataList = value;
                    RaisePropertyChanged("DataList");
                }
            }
        }

        public MainWindowViewModel()
        {
            DataList = GetDemoDataList(5);
        }

        public ObservableCollection<DemoDataModel> GetDemoDataList(int count)
        {
            var list = new ObservableCollection<DemoDataModel>();
            for (var i = 1; i <= count; i++)
            {
                var index = i % 6 + 1;

                var dataList = new List<DemoDataModel>();
                for (var j = 0; j < 3; j++)
                {
                    dataList.Add(new DemoDataModel
                    {
                        Index = j,
                        Name = $"SubName{j}",
                        ImgPath = $"/Resources/Images/{j % 5 + 1}.jpg",
                    });
                    for (var k = 0; k < 3; k++)
                    {
                        dataList[j].AddChild(new DemoDataModel
                        {
                            Index = k,
                            Name = $"SubSubName{k}",
                            ImgPath = $"/Resources/Images/{k % 5 + 1}.jpg",
                        });
                    }
                }
                var model = new DemoDataModel
                {
                    Index = i,
                    Name = $"Name{i}",
                    ImgPath = $"/Resources/Images/{i % 5 + 1}.jpg",
                    Remark = new string(i.ToString()[0], 10)
                };
                model.AddChildRange(dataList);
                list.Add(model);
            }

            return list;
        }
    }


    public class DemoDataModel : BaseTreeItemViewModel
    {
        public int Index { get; set; }

        public string Remark { get; set; }

        public string Field1
        {
            get; set;
        } = "Field1";

        public string Field2
        {
            get; set;
        } = "Field2";

        public string Field3
        {
            get; set;
        } = "Field3";

        public string Field4
        {
            get; set;
        } = "Field4";

        public string ImgPath { get; set; }
    }
}
